﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using NJL.IDAL;
using Royalsoft.DBUtility;//Please add references
namespace NJL.SQLServerDAL
{
    /// <summary>
    /// 数据访问类:NJL_CS_LIKES
    /// </summary>
    public partial class NJL_CS_LIKES : INJL_CS_LIKES
    {
        public NJL_CS_LIKES()
        { }
        #region  Method

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string AREA_CODE)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from NJL_CS_LIKES");
            strSql.Append(" where AREA_CODE=@AREA_CODE ");
            SqlParameter[] parameters = {
					new SqlParameter("@AREA_CODE", SqlDbType.VarChar,20)};
            parameters[0].Value = AREA_CODE;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(NJL.Model.NJL_CS_LIKES model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into NJL_CS_LIKES(");
            strSql.Append("AREA_CODE,AREA_NAME)");
            strSql.Append(" values (");
            strSql.Append("@AREA_CODE,@AREA_NAME)");
            SqlParameter[] parameters = {
					new SqlParameter("@AREA_CODE", SqlDbType.VarChar,20),
					new SqlParameter("@AREA_NAME", SqlDbType.VarChar,50)};
            parameters[0].Value = model.AREA_CODE;
            parameters[1].Value = model.AREA_NAME;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(NJL.Model.NJL_CS_LIKES model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update NJL_CS_LIKES set ");
            strSql.Append("AREA_NAME=@AREA_NAME");
            strSql.Append(" where AREA_CODE=@AREA_CODE ");
            SqlParameter[] parameters = {
					new SqlParameter("@AREA_NAME", SqlDbType.VarChar,50),
					new SqlParameter("@AREA_CODE", SqlDbType.VarChar,20)};
            parameters[0].Value = model.AREA_NAME;
            parameters[1].Value = model.AREA_CODE;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string AREA_CODE)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from NJL_CS_LIKES ");
            strSql.Append(" where AREA_CODE=@AREA_CODE ");
            SqlParameter[] parameters = {
					new SqlParameter("@AREA_CODE", SqlDbType.VarChar,20)};
            parameters[0].Value = AREA_CODE;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string AREA_CODElist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from NJL_CS_LIKES ");
            strSql.Append(" where AREA_CODE in (" + AREA_CODElist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public NJL.Model.NJL_CS_LIKES GetModel(string AREA_CODE)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 AREA_CODE,AREA_NAME from NJL_CS_LIKES ");
            strSql.Append(" where AREA_CODE=@AREA_CODE ");
            SqlParameter[] parameters = {
					new SqlParameter("@AREA_CODE", SqlDbType.VarChar,20)};
            parameters[0].Value = AREA_CODE;

            NJL.Model.NJL_CS_LIKES model = new NJL.Model.NJL_CS_LIKES();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["AREA_CODE"] != null)
                {
                    model.AREA_CODE = ds.Tables[0].Rows[0]["AREA_CODE"].ToString();
                }
                if (ds.Tables[0].Rows[0]["AREA_NAME"] != null)
                {
                    model.AREA_NAME = ds.Tables[0].Rows[0]["AREA_NAME"].ToString();
                }
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select AREA_CODE,AREA_NAME ");
            strSql.Append(" FROM NJL_CS_LIKES ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" AREA_CODE,AREA_NAME ");
            strSql.Append(" FROM NJL_CS_LIKES ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "NJL_CS_LIKES";
            parameters[1].Value = "AREA_CODE";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  Method
    }
}

